#include <stdio.h>
#include "sqlite3.h"



int loadOrSaveDb(sqlite3 *pInMemory, const char *zFilename,int isSave){

    int rc;
    sqlite3 *pFile;
    sqlite3_backup *pBackup;
    sqlite3 *pTo;
    sqlite3 *pFrom;
    rc = sqlite3_open(zFilename, &pFile);

    if( rc==SQLITE_OK ){

        pFrom = (isSave ? pInMemory : pFile);
        pTo= (isSave ? pFile: pInMemory);
        pBackup = sqlite3_backup_init(pTo, "sqlite1.db", pFrom, "sqlite.db");

        if( pBackup ){

            (void)sqlite3_backup_step(pBackup, -1);

            (void)sqlite3_backup_finish(pBackup);

        }

        rc= sqlite3_errcode(pTo);

    }

    (void)sqlite3_close(pFile);

    return rc;

}


int main()
{
    printf("Hello World!\n");
    sqlite3 *pInMemory=NULL;
    const char *zFilename="pers/sqlite.db";
    int ret=loadOrSaveDb(pInMemory,zFilename,0);
    printf("ret:%d",&ret);
    return 0;
}





